<?php
$_servername = 'http://'.$_SERVER["HTTP_HOST"];

function round_table($wd='100%', $c='EEEEEE', $bg='white', $w='5', $h='5', $pos='top', $others='') {
    if ($pos=='top') {
        $l = 'tl';$r='tr';
    } else {
        $l = 'bl';$r='br';
    }
    if (strlen($c)==6) $tbg="#$c";
    return '<table width="'. $wd .'" cellspacing="0" cellpadding="0"'.$others.'><tr><td><img alt="" src="/images/round/'.$c.'_'.$bg.'_'.$w.'x'.$h.'_'.$l.'.png" width="'.$w.'" height="'.$h.'" /></td><td width="100%" height="2" bgcolor="'.$tbg.'"><img width="1" height="1" alt="" src="/images/blank.gif" /></td><td><img alt="" src="/images/round/'.$c.'_'.$bg.'_'.$w.'x'.$h.'_'.$r.'.png" width="'.$w.'" height="'.$h.'" /></td></tr></table>';
}

function cn_substr($str,$strlen=10,$other=false) {
    $strlen *= 3;
    for($i=0;$i<$strlen;$i++)
    if(ord(substr($str,$i,1))>0xa0) $j++;
    if($j%3!=0) $strlen++;
    $rstr=substr($str,0,$strlen);
    if ((strlen($str)>$strlen) && $other) {$rstr.='……';}
    return $rstr;
}

function utf8_substr($str,$start) {
    $end = @func_get_arg(2);
    if (function_exists('mb_strimwidth')) {
        $end*=2;
        $end+=3;
        return mb_strimwidth($str, $start, $end, '...', 'UTF-8');
    }
    preg_match_all("/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|\xe0[\xa0-\xbf][\x80-\xbf]|[\xe1-\xef][\x80-\xbf][\x80-\xbf]|\xf0[\x90-\xbf][\x80-\xbf][\x80-\xbf]|[\xf1-\xf7][\x80-\xbf][\x80-\xbf][\x80-\xbf]/", $str, $ar);
    if($end) {
        return join("",array_slice($ar[0],$start,$end));
    } else {
        return join("",array_slice($ar[0],$start));
    }
}

function is_brand() {
    return strpos($_SERVER['REQUEST_URI'], '/brand/') !== false;
}
?>
